package com.zhen.gulimall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class MyRedissonConfig {

    /**
     * 所有对redisson 的操作 都是通过这个bean来操作 RedissonClient
     * @return
     * @throws IOException
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() throws IOException{
        // 创建配置
        Config config = new Config();
        // 单节点模式的创建
        // Redis url should start with (不安全连接)redis:// or （安全连接）rediss:// (for SSL connection)
        config.useSingleServer().setAddress("redis://192.168.189.129:6379");
        // 根据配置创建 RedissonClient 实例对象
        return Redisson.create(config);
    }
}
